<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<script language="JavaScript">

<%@ include file="/mc/common/jsutils.jsp" %>

//
//
//
  function doUserTemplateNewAction(myform) {
    myform.userTemplateId.value = 0;
    myform.forwardAction.value = '/ep/userTemplateList.do';
    myform.resetListSessionAttribute.value = 'userTemplateListResult';
    myform.action = "<c:url value="/ep/userTemplateNew.do"/>";
    myform.submit();
  }

//
//
//
  function doOneUserTemplateOnOffAction(oid, online, count) {
    if (online == false && count > 0 && !confirm('<bean-el:message key="ep.user.template.confirm.offline" bundle="ep.messages"/>')) return;
    document.userTemplateListForm.userTemplateId.value = oid;
    document.userTemplateListForm.setOnlineStatus.value = online;
    document.userTemplateListForm.forwardAction.value = '/ep/userTemplateList.do';
    document.userTemplateListForm.listSessionAttribute.value = 'userTemplateListResult';
    document.userTemplateListForm.action = "<c:url value="/ep/userTemplateOnOff.do"/>";
    document.userTemplateListForm.submit();
  }

//
//
//
  function doUserTemplateOnOffAction(myform, online) {
    if (online == false && !confirm('<bean-el:message key="ep.user.templates.confirm.offline" bundle="ep.messages"/>')) return;
    myform.userTemplateId.value = 0;
    myform.setOnlineStatus.value = online;
    myform.forwardAction.value = '/ep/userTemplateList.do';
    myform.listSessionAttribute.value = 'userTemplateListResult';
    myform.action = "<c:url value="/ep/userTemplateOnOff.do"/>";
    myform.submit();
  }

//
//
//
  function doOneUserTemplateDeleteAction(oid) {

    if (!confirm('<bean-el:message key="ep.user.template.confirm.delete" bundle="ep.messages"/>')) return;

    document.userTemplateListForm.userTemplateId.value = oid;
    document.userTemplateListForm.forwardAction.value = '/ep/userTemplateList.do';
    document.userTemplateListForm.listSessionAttribute.value = 'userTemplateListResult';
    document.userTemplateListForm.action = "<c:url value="/ep/userTemplateDelete.do"/>";
    document.userTemplateListForm.submit();
  }

//
//
//
  function doOneUserTemplateEditAction(oid) {
    document.userTemplateListForm.userTemplateId.value = oid;
    document.userTemplateListForm.forwardAction.value = '/ep/userTemplateList.do';
    document.userTemplateListForm.listSessionAttribute.value = 'UserTemplateListResult';
    document.userTemplateListForm.action = "<c:url value="/ep/userTemplateDetailsEdit.do"/>";
    document.userTemplateListForm.submit();
  }

//
//
//
function getFilePickerTimeStamp() {
  var now = new Date;
  var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() +
                       now.getHours() + now.getMinutes() + now.getSeconds() +
                       now.getMilliseconds();
  return timestamp;
}

//
//
//
function doReport(url) {
  var popup = window.open(url, 'report' + getFilePickerTimeStamp(), 'width=800,height=550,resizable=yes,scrollbars=yes,status=0');
  self.name = 'window' + '3D8F54DA7F122AF9360A54B55E121107';
  if (popup != null) {
    if (popup.opener == null) {
      popup.opener = self;
    }
  }
  return false;
}

</script>

<%
  String ctxPath = request.getContextPath();
%>

<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOffline" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.setOffline" bundle="ep.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOnline" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.setOnline" bundle="ep.messages"/>">
</c:set>
<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>
<c:set var="reportImg">
<img src="<%= ctxPath %>/ep/images/action/icon_report.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.report" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.report" bundle="ep.messages"/>">
</c:set>

<html-el:form action="/ep/userTemplateList.do">
<input type="hidden" name="userTemplateId"/>
<input type="hidden" name="setOnlineStatus"/>
<input type="hidden" name="forwardAction"/>
<input type="hidden" name="listSessionAttribute"/>
<input type="hidden" name="resetListSessionAttribute"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
   <td valign="top" width="100%">
      <div class="pageTitle">
        <bean-el:message key="ep.user.templates.manage.page.title" bundle="ep.messages"/>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>

      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="ep.user.templates" bundle="ep.messages"/>
        </span>
        <span class="right">
           <input type="button" class="titleButton" value='<bean-el:message key="button.new.usertemplate" bundle="ep.messages"/>'
            onclick="doUserTemplateNewAction(this.form);">
        </span>
      </div>
<c:if test="${not empty list}">
      <div class="globalButtonWrap">
         <input type="button" name="actionSelectAll" class="globalButton"
          onClick="check(this.form.userTemplateIds, this);"
          value="<bean-el:message key="button.selectAll" bundle="ep.messages"/>">
        <input type="button" name="actionSetOnline" class="globalButton"
          onClick="if (isAnyChecked(this.form.userTemplateIds, '<bean-el:message key="ep.user.templates.alert.atLeastOne" bundle="ep.messages"/>')) doUserTemplateOnOffAction(this.form, true);"
          value="<bean-el:message key="button.setOnline" bundle="ep.messages"/>">
        <input type="button" name="actionSetOffline" class="globalButton"
          onClick="if (isAnyChecked(this.form.userTemplateIds, '<bean-el:message key="ep.user.templates.alert.atLeastOne" bundle="ep.messages"/>')) doUserTemplateOnOffAction(this.form, false);"
          value="<bean-el:message key="button.setOffline" bundle="ep.messages"/>">
      </div>
</c:if>
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Checkboxes">&nbsp;</th>
          <th id="Name" align="left">
            <bean-el:message key="ep.header.name" bundle="ep.messages"/>
          </th>
          <th id="Description" align="left">
            <bean-el:message key="ep.header.description" bundle="ep.messages"/>
          </th>
          <th id="LastModifiedDate" align="left">
            <bean-el:message key="ep.header.lastModifiedDate" bundle="ep.messages"/>
          </th>
          <th id="Status" align="left">
            <bean-el:message key="ep.header.status" bundle="ep.messages"/>
          </th>
          <th id="Actions" align="left" nowrap>
            <bean-el:message key="ep.header.actions" bundle="ep.messages"/>
          </th>
        </tr>
<c:choose>
  <c:when test="${not empty list}">
    <c:forEach var="item" items="${list}" varStatus="status">
      <c:url var="viewUrl" value="/ep/userTemplateDetailsView.do">
        <c:param name="userTemplateId" value="${item.map.id}"/>
      </c:url>
      <c:url var="reportUrl" value="/ep/userWithUserTemplateReportList.do">
        <c:param name="userTemplateId" value="${item.map.id}"/>
      </c:url>

      <c:choose>
        <c:when test="${(status.count + 1) % 2 == 0}">
          <tr class="listEven">
        </c:when>
        <c:otherwise>
          <tr class="listOdd">
        </c:otherwise>
      </c:choose>
            <td headers="Checkboxes" align="center">
            <input type="checkbox" name="userTemplateIds"
              onClick="update(this.form.userTemplateIds, this.form.actionSelectAll);"
              value="<c:out value="${item.map.id}"/>"/>
          </td>
          <td headers="Name">
            <a href='<c:out value="${viewUrl}"/>'>
              <c:out value="${item.map.name}"/></a>
          </td>
          <td headers="Description"><c:out value="${item.map.description}"/></td>
          <td headers="LastModifiedDate">
            <bean:write name="item" property="lastModifiedDate" formatKey="format.datetime.short" bundle="mc.messages"/>
          </td>
          <td headers="Status">
      <c:choose>
        <c:when test="${item.map.status == 0}">
            <bean-el:message key="ep.label.offline" bundle="ep.messages"/>
        </c:when>
        <c:otherwise>
            <bean-el:message key="ep.label.online" bundle="ep.messages"/>
        </c:otherwise>
      </c:choose>
          </td>
          <td headers="Actions">
             <a href='#' onclick="doOneUserTemplateEditAction('<c:out value="${item.map.id}"/>');">
              <c:out value='${editImg}' escapeXml="false"/></a>
           <c:choose>
        <c:when test="${item.map.status == 0}">
            <a href='#' onclick="doOneUserTemplateOnOffAction('<c:out value="${item.map.id}"/>', true, <c:out value="${item.map.userCount}"/>);">
              <c:out value='${onlineImg}' escapeXml="false"/></a>
        </c:when>
        <c:otherwise>
            <a href='#' onclick="doOneUserTemplateOnOffAction('<c:out value="${item.map.id}"/>', false, <c:out value="${item.map.userCount}"/>);">
              <c:out value='${offlineImg}' escapeXml="false"/></a>
        </c:otherwise>
      </c:choose>
      <c:if test="${item.map.userCount <= 0}">
            <a href='#' onclick="doOneUserTemplateDeleteAction('<c:out value="${item.map.id}"/>');">
              <c:out value='${deleteImg}' escapeXml="false"/></a>
      </c:if>
      <c:if test="${item.map.userCount > 0}">
            <a href='#' onclick="doReport('<c:out value="${reportUrl}"/>')"><c:out value='${reportImg}' escapeXml="false"/></a>
      </c:if>
          </td>
        </tr>
    </c:forEach>
  </c:when>
  <c:otherwise>
        <tr class="listOdd">
          <td align="center" colspan="6">
            <bean-el:message key="ep.user.templates.noFound" bundle="ep.messages"/>
          </td>
        </tr>
  </c:otherwise>
</c:choose>
      </table>
      <c:if test="${not empty list}">
      <%@ include file="/mc/common/pager.jsp" %>
      </c:if>
    </td>
  </tr>
</table>
</html-el:form>